package com.example.jh352160.surfingtv.mypage.customView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.jh352160.surfingtv.R;

/**
 * Created by jh352160 on 2016/7/26
 */

public class MyPageSettingItem extends LinearLayout {

    Context context;
    TextView textView;
    EditText editText;
    Button button;
    Boolean isMale;

    public MyPageSettingItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public MyPageSettingItem(Context context) {
        super(context);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.mypage_setting_item, this);
        textView = (TextView) findViewById(R.id.textView);
        editText = (EditText) findViewById(R.id.edittext);
        button = (Button) findViewById(R.id.button);
    }

    public void setView(String name, String hint, int type) {
        textView.setText(name);
        editText.setHint(hint);
        editText.setInputType(type);
    }

    public void setView(String name, String hint, int type, boolean haveButton) {
        textView.setText(name);
        editText.setHint(hint);
        editText.setInputType(type);
        button.setVisibility(VISIBLE);
        if (!haveButton) {
            button.setBackgroundResource(R.drawable.mypage_edit_male);

        }
    }

    public void setView(String name, String hint, int type, boolean haveButton, final boolean isMale) {
        textView.setText(name);
        editText.setHint(hint);
        editText.setInputType(type);
        editText.setVisibility(GONE);
        button.setVisibility(VISIBLE);
        button.setText("");
        this.isMale = isMale;
        setSex();
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                changeSex();
                setSex();
            }
        });
    }

    private void setSex() {
        if (isMale) {
            button.setBackgroundResource(R.drawable.mypage_edit_male);
        } else {
            button.setBackgroundResource(R.drawable.mypage_edit_female);
        }
    }

    private void changeSex() {
        isMale = !isMale;
    }

}
